<template>
  <div id="app">
    <div class="container">
      <div class="close"><span class="iconfont iconicon-test"></span></div>
      <div class="logo"><span class="iconfont iconnew"></span></div>
      <div class="inputs">
        <hmInput
          ref="username"
          v-model="user.username"
          placeholder="请输入手机号"
          :reg="/^1[3,4,5,6,7,8,9]\d{9}$/"
        ></hmInput>
        <!-- 声明变量nickname 双向绑定在昵称输入框中 -->
        <hmInput ref="nickname"  v-model="user.nickname" placeholder="请输入昵称"></hmInput>
        <hmInput
          ref="password"
          v-model="user.password"
          :reg="/^.{3,10}$/"
          type="password"
          placeholder="请输入密码"
        ></hmInput>
      </div>
      <p class="tips">
        已有账号？
        <a href="#/login" class="">去登录</a>
      </p>
      <!-- <div icon="wap-home" class="button" round block>登录按钮</div> -->
      <van-button type="primary" round block @click="registerFn"
        >注册</van-button
      >
    </div>
  </div>
</template>

<script>
import { register } from "../api/user";
export default {
  data() {
    return {
      user: {
        username: "",
        password: "",
        nickname: "",
      },
    };
  },
  methods:{
    //   注册
    registerFn(){
        //判断用户输入内容是否合法
        if(!this.$refs.username.isOK){
            this.$toast.fail('手机号有误,请重新检查后再输')
            return
        }
       
         if(!this.$refs.nickname.isOK){
            
            this.$toast.fail('至少输入一位数')
            return
        }
          if(!this.$refs.password.isOK){
            this.$toast.fail('密码号必须是3-10位数,请重新检查后再输')
        return
        }
        // 调用注册接口
        register(this.user).then(res=>{
            console.log(522222,res);
            if(res.data.message === '注册成功'){
                // 跳转到登录页
                this.$toast.success(res.data.message)
                this.$router.push({
                    path:'/login'
                })
            }else{
                this.$toast.fail(res.data.message)
            }
        })
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  padding: 20px;
}
.close {
  span {
    font-size: (27 / 360) * 100vw;
  }
}
.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: (126 / 360) * 100vw;
    color: #d81e06;
  }
}
.inputs {
  input {
    // margin-bottom: 20px;
    display: block;
    margin: 0 auto 20px auto;
  }
}
.tips {
  text-align: right;
  margin-bottom: 20px;
  a {
    color: #3385ff;
  }
}
</style>